package com.bilibili.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bilibili.dao.FollowingGroupMapper;
import com.bilibili.dao.UserFollowingMapper;
import com.bilibili.domain.constant.UserConstant;
import com.bilibili.domain.entity.FollowingGroup;
import com.bilibili.service.FollowingGroupService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* @author www
* @description 针对表【t_following_group(用户关注分组表)】的数据库操作Service实现
* @createDate 2024-06-04 15:12:44
*/
@Service
public class FollowingGroupServiceImpl extends ServiceImpl<FollowingGroupMapper, FollowingGroup>
    implements FollowingGroupService {
    @Resource
    private FollowingGroupMapper followingGroupMapper;
    @Resource
    private UserFollowingMapper userFollowingMapper;

    LambdaQueryWrapper<FollowingGroup> wrapper = new LambdaQueryWrapper<>();

    @Override
    public FollowingGroup getByType(String type) {
        wrapper.eq(FollowingGroup::getType,type);
        return followingGroupMapper.selectOne(wrapper);
    }

    @Override
    public Long addUserFollowingGroups(FollowingGroup followingGroup) {
        followingGroup.setCreateTime(new Date());
        followingGroup.setUpdateTime(new Date());
        followingGroup.setType(UserConstant.USER_FOLLOWING_GROUP_TYPE_USER);
        followingGroupMapper.insert(followingGroup);
        return followingGroup.getId();
    }

    @Override
    public List<FollowingGroup> getUserFollowingGroups(Long userId) {
        wrapper.eq(FollowingGroup::getUserId,userId);
        return followingGroupMapper.selectList(wrapper);
    }
}




